package com.itqf.Util.requestHeader;

import com.itqf.Util.JwtUtile.JwtUtils;
import com.itqf.entity.User;
import io.jsonwebtoken.Claims;
import org.junit.Test;

import javax.servlet.http.HttpServletRequest;
/** 
* @Description: 获取请求头中的token 并解析出user对象 取得userid 
* @Param:  
* @return:  
* @Author: 陈岗阳
* @Date: 2019/10/20 
*/ 
public class RequestHeaderUtil
{
    public User getheader(HttpServletRequest request)
    {
        //获取请求头里面的x-access-token 的信息
        String token = request.getHeader("x-access-token");
        //检测token是否失效
        Claims claims = JwtUtils.checkToken(token);
        if (claims!=null)
        {
            JwtUtils jwtUtils=new JwtUtils();
            //token没有失效即解析toekn返回User 对象
            final User user = jwtUtils.TestCheck(token);
            return user;
        }
        //没有检测出来
        return null;
    }
}


